<template>
  <div class="GComprehensiveJudgeList">
    <filterPanel filterName="GComprehensiveJudgeListFilter" filterTitle="综合研判运单查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GComprehensiveJudgeListTable" :tableLoading="loading" tableTitle="综合研判运单列表"
                :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="showModel">综合研判设置</zy-button>
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
    <setModel title="综合研判设置" :show="show" @close="close" ></setModel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";
	import setModel from "./setModel";
	export default {
		name: "GComprehensiveJudgeList",
		props: {},
		data() {
			return {
				currentPath: '/judge_comprehensive_list',
				filterData: [
					{
						title: '运单号',
						name: 'logistics_no',
						type: 'input',
						value: '',
						maxlength: '100',
						isShow: true,
						isSelected: true
					},
					{
						title: '运单类型',
						name: 'logistics_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '收件', value: '1'},
							{label: '寄件', value: '2'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '承运物流公司',
						name: 'company_name',
						type: 'input',
						value: '',
						maxlength: '100',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						name: 'company_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流', value: 0},
							{label: '快递', value: 1},
							{label: '分拣中心', value: 2},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '研判评分',
						name: 'score',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '预警方式',
						name: 'early_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '站内信', value: '1'},
							{label: '短信', value: '2'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '预警人员',
						name: 'plc_name',
						type: 'select',
						optionList: [],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '研判时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					logistics_no: '',
					logistics_type: '',
					company_name: '',
					company_type: '',
					score: '',
					early_type: '',
					plc_name: '',
					time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '运单号',
						width: 180,
						name: 'logistics_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '运单类型',
						width: 120,
						name: 'logistics_type_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '承运物流企业',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 120,
						name: 'type_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '研判评分',
						width: 120,
						name: 'score',
						isShow: true,
						isSelected: true
					},
					{
						title: '标记颜色',
						width: 120,
						name: 'judge_color',
						type: 'color',
						isShow: true,
						isSelected: true
					},
					{
						title: '预警方式',
						width: 120,
						name: 'early_type_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '预警人员',
						width: 120,
						name: 'police_names',
						isShow: true,
						isSelected: true
					},
					{
						title: '研判时间',
						width: 200,
						name: 'judge_time_cn',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 100,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: '',
				show: false,
			};
		},
		computed: {
			postData() {
				let data = {
					logistics_no: this.form.logistics_no,
					logistics_type: this.form.logistics_type,
					company_name: this.form.company_name,
					company_type: this.form.company_type,
					score: this.form.score,
					early_type: this.form.early_type,
					plc_name: this.form.plc_name,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_created_time = this.form.time[0] / 1000;
					data.end_created_time = this.form.time[1] / 1000;
				}
				return data;
			},
			...mapGetters(['authority']),
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].m;
			},
		},
		watch: {},
		components: {setModel},
		methods: {
			getPoliceData() {
				this.$axios.post(this.$api.g_listContactPolice, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.setFilterData({
							plc_name: data.list.filter(item => {
								item.value = item.name;
								item.label = item.name
								return item;
							}),
						}, ['plc_name']);
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			setFilterData(val, nameList) {
				for (let item of this.filterData) {
					if (nameList.indexOf(item.name) !== -1) {
						item.optionList = val[item.name]
					}
				}
			},
			showModel() {
				this.show = true;
			},
			close(isRefresh) {
				if (isRefresh)
					this.getData()
				this.show = false
			},
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.g_comprehensiveList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						let arr = ['物流', '快递', '分拣中心']
						this.tableData = data.list.filter(item => {
							item.type_desc = arr[item.company_type];
							item.detail = this.isLook || true;
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0
						this.tableData = [];
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				this.$toRoutePath({
					path: "/receive_list/receive_list_detail",
					edit: true,
					query: {
            logistics_id: data.logistics_id
          }
				});
			},
		},
		mounted() {
			this.getData();
			this.getPoliceData()
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/judgeManage/comprehensiveJudge/index.less">

</style>
